$("#brand").change(function() {
	var id = $(this).val();
	$("#series").empty();
	if(id){
		$("#series").removeAttr("disabled");
		var option = document.createElement("option");
		option.text = "正在加载...";
		option.value = "";
		$("#series")[0].options.add(option);
		$.ajax({
			url : contextPath+"/getSeries/" + id,
			dataType : 'json',
			cache : false,
			success : function(result) {
				$("#series").empty();
				var empty = document.createElement("option");
				empty.text = "请选择车系";
				empty.value = "";
				$("#series")[0].options.add(empty);
				for ( var i in result) {
					var option = document.createElement("option");
					option.text = result[i].name;
					option.value = result[i].enname;
					$("#series")[0].options.add(option);
				}
			},
			error:function(){
				$("#series").empty();
				var option = document.createElement("option");
				option.text = "加载失败";
				option.value = "";
				$("#series")[0].options.add(option);
			}
		});
	}
	else{
		var option = document.createElement("option");
		option.text = "请选择车系";
		option.value = "";
		$("#series")[0].options.add(option);
		$("#series").attr("disabled","diabled");
	}
	//$("#brand").val($(this).find("option:selected").val()==''?'':$(this).find("option:selected").text().substring(2));
});
$.ajax({
	url : contextPath+"/getEvaluateBrands",
	dataType : 'json',
	cache : true,
	ifModified: false,
	success : function(result) {
		$("#evaluateBrand").empty();
		var option = document.createElement("option");
		option.text = "请选择品牌";
		option.value = "";
		$("#evaluateBrand")[0].options.add(option);
		for(var i in result){
			var option = document.createElement("option");
			option.text = i;
			option.value = result[i];
			$("#evaluateBrand")[0].options.add(option);
		}
	},
	error:function(){
	}
});
$("#evaluateBrand").change(function() {
	var evaluateBrand = $(this).val();
	$("#evaluateSeries").empty();
	var option = document.createElement("option");
	option.text = "正在加载...";
	option.value = "";
	$("#evaluateSeries")[0].options.add(option);
	$.ajax({
		url : contextPath+"/getEvaluateSeries/" + + encodeURI(encodeURI(evaluateBrand)),
		dataType : 'json',
		cache : false,
		//async:false,//同步
		success : function(result) {
			$("#evaluateSeries").empty();
			var option = document.createElement("option");
			option.text = "请选择车系";
			option.value = "";
			$("#evaluateSeries")[0].options.add(option);
			$("#evaluateDisplacement").empty();
			var option = document.createElement("option");
			option.text = "请选择排量";
			option.value = "";
			$("#evaluateDisplacement")[0].options.add(option);
			for(var i in result){
				var option = document.createElement("option");
				option.disabled = "disabled";
				option.text = i;
				option.value = "";
				$("#evaluateSeries")[0].options.add(option);
				var model = result[i];
				for(var j in model){
					var option = document.createElement("option");
					option.text = "　" + model[j];
					option.value = j;
					$("#evaluateSeries")[0].options.add(option);
				}
			}
		},
		error:function(){
			$("#evaluateSeries").empty();
			var option = document.createElement("option");
			option.text = "加载失败";
			option.value = "";
			$("#evaluateSeries")[0].options.add(option);
		}
	});
});
$("#evaluateSeries").change(function() {
	var seriesId = $(this).val();
	$("#evaluateDisplacement").empty();
	var option = document.createElement("option");
	option.text = "正在加载...";
	option.value = "";
	$("#evaluateDisplacement")[0].options.add(option);
	$.ajax({
		url : contextPath+"/getEvaluateDisplacements/" + seriesId,
		dataType : 'json',
		cache : false,
		//async:false,//同步
		success : function(result) {
			$("#evaluateDisplacement").empty();
			var option = document.createElement("option");
			option.text = "请选择排量";
			option.value = "";
			$("#evaluateDisplacement")[0].options.add(option);
			for(var i in result){
				var option = document.createElement("option");
				option.text = result[i];
				option.value = result[i];
				$("#evaluateDisplacement")[0].options.add(option);
			}
		},
		error:function(){
			$("#evaluateDisplacement").empty();
			var option = document.createElement("option");
			option.text = "加载失败";
			option.value = "";
			$("#evaluateDisplacement")[0].options.add(option);
		}
	});
});
//限时特卖轮播
var carouselIndex = 1;
$(".sael-wrap .hd ul li").click(function(){
	carouselIndex = $(this).attr("index");
	carousel();
	window.clearInterval(interval);
	interval = setInterval(carousel,6000);
});
var carousel = function(){
	if(promoCars >3){
		var index = carouselIndex*3 <= promoCars-3 ? (carouselIndex*3) : (promoCars-3);
		var left = index*(-247);
		$(".sael-product .sael-pro-wrap").animate({
			left: left
		}, 500);
		$(".sael-wrap .hd ul li").removeClass("crt-carousel");
		$(".sael-wrap .hd ul li[index="+carouselIndex+"]").addClass("crt-carousel");
		if(index >= promoCars-3)
			carouselIndex = 0;
		else
			carouselIndex ++;
	}
};  
var interval = setInterval(carousel,6000);
$(".sael-product").mouseover(function(){
	window.clearInterval(interval);
});
$(".sael-product").mouseout(function(){
	interval = setInterval(carousel,6000);
});
//热卖车型切换
$(".hot-wrap .hd ul li").mouseover(function(){
	var old = $(".hot-wrap .hd ul li.crt-tab").attr("href");
	$(old).hide();
	$(".hot-wrap .hd ul li").removeClass("crt-tab");
	$(this).addClass("crt-tab");
	//$(".hot-pro-wrap").hide();
	var show = $(this).attr("href");
	$(show).fadeIn(100);
});

//热卖车型切换
$(".coo-wrap .hd ul li").mouseover(function(){
	var old = $(".coo-wrap .hd ul li.crt-tab").attr("href");
	$(old).hide();
	$(".coo-wrap .hd ul li").removeClass("crt-tab");
	$(this).addClass("crt-tab");
	var show = $(this).attr("href");
	$(show).show();
});
$("#filter-submit").click(function(){
	var brand =  $("#brand").val();
	var series = $("#series").val();
	var url = "";
	if(brand)
		url += brand + "/";
	if(series)
		url += series +"/";
	if(url){
		url = contextPath +"/" + url;
	}
	else
		url = contextPath + "/buycar/";
	window.location.href = url;
});